<template>
  <div class="reservations">
    <div class="header border-bottom" v-if="title">
      <span class="iconfont icon-header">&#xe609;</span>
      {{title}}
    </div>
    <div class="item border-bottom" v-for="item in showList()" :key="item.id">
      <div class="item-info">
        <p class="title">{{item.title}}</p>
        <p class="desc" v-if="item.desc">{{item.desc | formatDesc}}</p>
      </div>
      <div class="price">
        ￥{{item.price}}
        <span>起</span>
      </div>
    </div>
    <div class="show-more" @click="showMoreClick" v-if="showMore">查看剩余产品</div>
  </div>
</template>

<script>
export default {
  name: "DetailReservations",
  data() {
    return {
      showMore: true,
      reserList: []
    };
  },
  props: {
    title: String,
    list: Array
  },
  filters: {
    formatDesc(desc) {
      return desc.substring(0, 15).concat("...");
    }
  },
  watch: {
    list(newVal, oldVal) {
      this.reserList = newVal;
    }
  },
  methods: {
    showMoreClick() {
      this.showMore = false;
    },
    showList() {
      let result = [];
      if (this.showMore) {
        this.reserList.forEach((item, index) => {
          if (index < 2) result.push(item);
        });
        return result;
      }
      return this.reserList;
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '~@/assets/style/variables'

.reservations
  width: 100%
  padding: 0 0.2rem
  background: #fff
  .header
    height: $headerHeight
    line-height: $headerHeight
    font-size: 0.32rem
    .icon-header
      color: #ff6e6e
  .item
    display: flex
    flex-direction: row
    justify-content: space-between
    padding: 0.3rem 0
    .item-info
      font-size: 0.3rem
      .desc
        color: #616161
        font-size: 0.24rem
    .price
      font-size: 0.4rem
      color: #ff9917
      text-align: center
      span
        font-size: 0.24rem
        color: #616161
        margin-left: -0.06rem
  .show-more
    font-size: 0.3rem
    text-align: center
    height: $headerHeight
    line-height: $headerHeight
</style>